﻿//===================================================================
//
// 微码北京科技配置类
//
// 标识：Eric.cao20071227
//
// 修改日期：
//
//===================================================================

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;

namespace BaseSet.Framework.Config
{
    /// <summary>
    /// 配置文件操作类
    /// </summary>
    public class Config
    {
        public Config()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        /// <summary>
        /// 返回系统表前缀
        /// </summary>
        /// <returns>表前缀</returns>
        public static string GetConfig(string nodeName)
        {
            string node = System.Configuration.ConfigurationManager.AppSettings["" + nodeName + ""].ToString();

            return node;
        }

        /// <summary>
        ///  更改webconfig中节点的值
        /// </summary>
        /// <param name="nodeValue">更改的值</param>
        /// <param name="nodeName">结点名称</param>
        public static void UpdateConfig(string nodeName, string nodeValue)
        {
            XmlDocument doc = new XmlDocument();

            string configFile = System.Web.HttpContext.Current.Server.MapPath("..\\") + "\\Web.config";

            doc.Load(configFile);

            // C/S结构下
            //doc.Load(Application.ExecutablePath + ".config");
            XmlNode node = doc.SelectSingleNode(@"//add[@key='" + nodeName + "']");
            XmlElement ele = (XmlElement)node;
            ele.SetAttribute("value", nodeValue);


            // C/S结构下

            //doc.Save(Application.ExecutablePath + ".config");
            doc.Save(configFile);

        }
    }
}